#include "stdafx.h"
#include "CircleObject.h"

CCircleObject::CCircleObject(b2World* world) : CBaseObject(world)
,m_bIsSolid(false)
{}

CCircleObject::~CCircleObject()
{}

void CCircleObject::Initialize()
{}

void CCircleObject::Draw()
{
	m_Pos = core::position2df(m_pB2Body->GetPosition().x, m_pB2Body->GetPosition().y);		
	if(m_bIsSolid)
	{
		CRenderVideo::GetInstance()->DrawCircle(m_Pos, m_fRadius, m_Color);
	}
	else
	{
		CRenderVideo::GetInstance()->DrawCircleLine(m_Pos, m_fRadius, m_Color);
	}
}


void CCircleObject::SetCircle(core::position2df& pos, float radius)
{
	m_Pos = pos;
	m_fRadius = radius;
}

void CCircleObject::SetSolid(bool isSolid)
{
	m_bIsSolid = isSolid;
}

void CCircleObject::GenB2()
{	
	m_BodyDef.position.Set(m_Pos.X, m_Pos.Y);
	m_pB2Body = m_pB2World->CreateBody(&m_BodyDef);	
	
	m_ShapeDef.radius = m_fRadius;
	if(m_fDensity > -30000)
	{
		m_ShapeDef.density = m_fDensity;
	}
	if(m_Friction > -30000)
	{
		m_ShapeDef.friction = m_Friction;
	}
	if(m_Restitution > -30000)
	{
		m_ShapeDef.restitution = m_Restitution;
	}

	m_pShape = (b2CircleShape* )m_pB2Body->CreateShape(&m_ShapeDef);

	if(m_fDensity > -30000)
	{
		m_pB2Body->SetMassFromShapes();
	}
}